<template>
    <el-dialog
        :visible.sync="dialogVisible"
        title="订单支付"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
        width="500px"
    >
        <el-form ref="formRef" :model="formData" :rules="rules" label-width="80px">
            <el-form-item label="支付方式" prop="expressName">
                <el-select v-model="formData.payType" filterable placeholder="请选择" style="width:200px;">
                    <el-option
                        v-for="item in payTypeList"
                        :key="item.code"
                        :label="item.name"
                        :value="item.code"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="交易号" prop="transactionId">
                <el-input v-model="formData.transactionId"/>
            </el-form-item>

            <el-form-item label="备注" prop="payRemark">
                <el-input v-model="formData.payRemark" type="textarea"/>
            </el-form-item>

            <el-form-item>
                <el-popconfirm :title="'确定保存吗？'" @onConfirm="submitForm()">
                    <el-button slot="reference" type="primary">保存</el-button>
                </el-popconfirm>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
import {OrderApi} from '@/api/food/order'

export default {
    name: 'MallOrderPay',
    components: {},
    data() {
        return {
            formData: {
                orderNo: '',
                payType: '',
                transactionId: '',
                payRemark: ''
            },
            rules: {
                payType: [
                    {required: true, message: '请选择支付方式', trigger: 'blur'}
                ]
            },
            dialogVisible: false,
            payTypeList: []
        }
    },
    methods: {
        // 显示组件
        showUpdate(orderNo) {
            this.dialogVisible = true

            this.formData.orderNo = orderNo
            if (this.$refs['formRef'] !== undefined) {
                this.$refs['formRef'].resetFields()
            }

            this.getPayTypeList()
        },

        getPayTypeList() {
            OrderApi.getOrderFilter().then((response) => {
                this.payTypeList = response.payTypeList
            })
        },

        // 提交表单
        submitForm() {
            const that = this
            that.$refs['formRef'].validate((valid) => {
                if (valid) {
                    OrderApi.payOrder(that.formData).then((response) => {
                        that.dialogVisible = false
                        that.$emit('refresh')
                    })
                }
            })
        }
    }
}
</script>

<style scoped>
.avatar-uploader .el-upload {
    width: 100px;
    height: 100px;
    border: 1px dashed var(--el-border-color);
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload img {
    width: 100px;
    height: 100px;
}

.avatar-uploader .el-upload:hover {
    border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    text-align: center;
    line-height: 100px;
    border: 1px dashed #CCC;
    border-radius: 6px;
}
</style>
